package com.youmeek.ssm.module.user.controller;

import com.youmeek.ssm.module.user.pojo.Account;
import com.youmeek.ssm.module.user.service.impl.AccountService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 作者：13687
 * 日期：2017/5/20
 * 项目：ssm
 * 描述：账户登陆
 */
@Controller
@RequestMapping("/account")
public class AccountController extends BaseAction{

	@Resource
	private AccountService accountService;


	@RequestMapping("/login")
	public String login(Account account, HttpServletRequest request, HttpSession session) {
		System.out.println(account.toString());
		Account acc = accountService.login(account);
		if (acc != null) {
//			记住账户信息（保存到session中）
			session.setAttribute("acc", acc);
		} else {
//			错误提示
//			request.setAttribute("msg","登陆失败");
			System.out.println("这里掉自己 会出现死循环");
//			return "login";
//			return "forward:main";
		}
		return "main";
	}
	@RequestMapping("/loginaction")
	public String login(Account account, HttpServletRequest httpServletRequest){
		System.out.println(account.toString());
		Account user = accountService.login(account);
		if (user != null) {
			httpServletRequest.setAttribute("msg","登陆失败");
			return "main";
		}
		httpServletRequest.setAttribute("msg","登陆失败");
		return "login";
	}

	@RequestMapping("/accountlist")
	public String accountlist(){
		return "accountlist";
	}
}
